package com.business_clean.ui.adapter.circle;

import android.graphics.Rect;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.SizeUtils;
import com.business_clean.R;
import com.business_clean.app.uitl.GlideUtil;
import com.business_clean.app.weight.CustomAvatarView;
import com.business_clean.data.mode.circle.ChatMessage;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

/**
 * 用于聊天界面
 */
public class ChatAdapter extends BaseMultiItemQuickAdapter<ChatMessage, BaseViewHolder> {
    public static final int TYPE_LEFT = 1;
    public static final int TYPE_RIGHT = 2;
    public static final int TYPE_DATE = 3;

    private RecyclerView recyclerView;

    public ChatAdapter(RecyclerView recyclerView) {
        super(null);
        this.recyclerView = recyclerView;
        addItemType(TYPE_LEFT, R.layout.item_chat_message_left);
        addItemType(TYPE_RIGHT, R.layout.item_chat_message_right);
        addItemType(TYPE_DATE, R.layout.item_chat_message_date);
        addChildClickViewIds(R.id.iv_item_chat_pic);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChatMessage item) {
        if (item.getItemType() != TYPE_DATE) {

            CustomAvatarView avatarView = helper.getView(R.id.iv_item_chat_avatar);
            avatarView.setAvatar(item.getAvatar(), item.getUser_name());
            avatarView.getAvatarText().setTextSize(16f);

            //image
            ImageView imageView = helper.getView(R.id.iv_item_chat_pic);

            //这里
            ImageView ivPlay = helper.getView(R.id.iv_item_chat_play);

            //加载缩略图
            if ("1".equals(item.getMessage_type())) {//1 是图片 2是视频
                ivPlay.setVisibility(View.GONE);
                GlideUtil.loadCirclePic(imageView.getContext(), item.getPic_thumb(), imageView, R.mipmap.icon_base_placeholder_working, 4);
            } else {
                ivPlay.setVisibility(View.VISIBLE);
                GlideUtil.loadCirclePic(imageView.getContext(), item.getVideo_cover_url(), imageView, R.mipmap.icon_base_placeholder_working, 4);
            }
        }


        switch (item.getItemType()) {
            case TYPE_LEFT:
                helper.setText(R.id.tv_item_chat_text, item.getAct_type_name());
                break;
            case TYPE_RIGHT:
                helper.setText(R.id.tv_item_name, item.getUser_name())
                        .setText(R.id.tv_item_job_name, item.getJob_name())
                        .setText(R.id.tv_item_chat_text, item.getAct_type_name());
                break;
            case TYPE_DATE:
                helper.setText(R.id.tv_item_chat_date, item.getCreate_time());
                break;
        }
    }


}